#!/bin/bash
echo "=========================="
echo "        MidService        "
echo "=========================="
count=`ps -ef|grep midservice|grep -v grep|wc -l`
if [ $count -gt 0 ];then
echo "MidService is already exists!"
exit
fi
apps_home=`dirname $0`/..
log_path=`pwd`/log/midservice.log
cp=$apps_home/etc/:$apps_home/lib/*
echo "Log path:"$log_path
nohup java -Xmx256M  -cp "$cp" com.xyzq.mid.Main midservice 1>/dev/null 2>&1 &

loop_count=0
while true
do
    if [ ! -f "$log_path" ]; then
      sleep 1
      if [ $loop_count -lt 10 ];then
        loop_count=$(($loop_count+1))
        continue
      else
        echo "ERROR:Start failure!"
        exit      
      fi
    else
      break
    fi
done  
tail -f -n 0 $log_path